<html>
<head><meta charset="utf-8"><title>async-read via generators · wg-async-foundations · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/index.html">wg-async-foundations</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/async-read.20via.20generators.html">async-read via generators</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="196221201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/async-read%20via%20generators/near/196221201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/async-read.20via.20generators.html#196221201">(May 04 2020 at 18:31)</a>:</h4>
<p><span class="user-mention" data-user-id="204219">@Matthias247</span> when it comes to dealing with hand-written pin impls, I agree with you; it seems like the solution for <code>Stream</code> is to support a generator-based syntax. I'm not sure about async-read and async-write.</p>



<a name="196222556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/async-read%20via%20generators/near/196222556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/async-read.20via.20generators.html#196222556">(May 04 2020 at 18:42)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> I've talked about this before, but you can also write asyncread and asyncwrite via generator syntax</p>



<a name="196222623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/async-read%20via%20generators/near/196222623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/async-read.20via.20generators.html#196222623">(May 04 2020 at 18:42)</a>:</h4>
<p>if generators get the full set of abilities I'd like them to have, that is</p>



<a name="196222758"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/async-read%20via%20generators/near/196222758" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/async-read.20via.20generators.html#196222758">(May 04 2020 at 18:43)</a>:</h4>
<p>However, they do have a similar issue to the io_uring stuff that the easiest-to-use design is one which offers a buffer which will continue to be available in future <code>poll</code>s</p>



<a name="196223346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/async-read%20via%20generators/near/196223346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/async-read.20via.20generators.html#196223346">(May 04 2020 at 18:46)</a>:</h4>
<p>interesting</p>



<a name="196223435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/async-read%20via%20generators/near/196223435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/async-read.20via.20generators.html#196223435">(May 04 2020 at 18:47)</a>:</h4>
<p>I'm curious to hear more about how you see that working, <span class="user-mention" data-user-id="127859">@Taylor Cramer</span></p>



<a name="196226036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/async-read%20via%20generators/near/196226036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthias247 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/async-read.20via.20generators.html#196226036">(May 04 2020 at 19:06)</a>:</h4>
<p>That may be possible. The main concern that I however have there is that yet another language feature is required to make up for lacks in the other language feature.</p>
<p>Let's compare Rust here with other languages: In C# or Kotlin people can just have an <code>IStream/etc</code> interface, the method there has an additional <code>async/suspend/etc</code> modifier,  and can implement the method as usual.</p>
<p>If someone in my team asks me now how to do it this in Rust, I would start with</p>
<ul>
<li>You need to implement the <code>poll</code> function manually. You can't use <code>async</code>. Then everyone needs to learn about <code>poll/Context/Waker/etc</code>.</li>
<li>We could then go on and implement something generator like - but now everyone needs to understand about generators. Crates like <code>async_stream</code> make this somewhat tolerable, but it's still yet another thing to learn.</li>
<li>The same applies for solutions where we would move to other IO traits which make use of GATs. Then I imagine conversations like:<ul>
<li>"How do I make this an interface?"</li>
<li>"That does only work with GATs"</li>
<li>"What are GATs?"</li>
<li>"I actually don't know it myself"</li>
</ul>
</li>
</ul>
<p>I want people who are domain experts in building IO heavy services  to use async Rust. Those are often new to Rust, and not necessarily people who are also experts in language design, and aware of advanced constructs. So throwing too much jargon at them in order to "just wrap a Stream in another Stream" might be rather intimidating</p>



<a name="196228360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/async-read%20via%20generators/near/196228360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthias247 <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/async-read.20via.20generators.html#196228360">(May 04 2020 at 19:26)</a>:</h4>
<p>And I'm fully aware that there is no easy solution for this problem at the moment - and I myself also don't have one. I just wanted to voice that all those traits are not really a great fit. They have their benefits (allow trait objects), but also their drawbacks (comparability is poor).</p>



<a name="196240668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/async-read%20via%20generators/near/196240668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Taylor Cramer <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/async-read.20via.20generators.html#196240668">(May 04 2020 at 21:11)</a>:</h4>
<p><span class="user-mention" data-user-id="204219">@Matthias247</span> I'm curious to take a look at other ecosystems that you think have solved this problem well and learn from them. I'm moderately familiar with C# and Kotlin's interfaces, but I'm not sure I understand the cognitive load distinction between future Rust's <code>async gen fn</code> (<code>async fn</code> + <code>gen fn</code>) and what you get with <code>IStream</code>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>